package com.mytest.service;

import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class MovieService {

    public synchronized void method(){

        System.out.println("start");
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("end");

    }

    public synchronized void method1(String string){

        SimpleDateFormat date = new SimpleDateFormat("yyyy-mm-dd  HH:mm:ss");
        Thread thread = Thread.currentThread();
        System.out.println(date.format(new Date()) + " " + thread+" method1 start param="+string);

        try {
            Thread.sleep(20000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        if ("true".equals(string)){
            method2(string);
        }
        System.out.println(date.format(new Date()) + " " + thread+" method1 end param="+string);
    }

    public synchronized void method2(String string){

        SimpleDateFormat date = new SimpleDateFormat("yyyy-mm-dd  HH:mm:ss");
        Thread thread = Thread.currentThread();
        System.out.println(date.format(new Date()) + " " + thread+" method2 start param="+string);

        try {
            Thread.sleep(20000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        if ("false".equals(string)){
            method1(string);
        }
        System.out.println(date.format(new Date()) + " " + thread+" method2 end param="+string);

    }
}
